Imports DAL
Imports MyClasses
Imports System.Configuration
Imports BAL

Public Class frmSchemeMaster
    Public intSchemeID As Integer
    Public itemid As Integer
    Public strWindowFlag As String = ""

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Try
            Me.Close()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "btnClose_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub ccmDItemname_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ccmDItemname.KeyDown
        Try
            If e.Alt Then Exit Sub
            'If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            If e.KeyCode = Keys.Enter Then dtpickerFrom.Focus()
            'ccmbFreeItem.Text = ccmDItemname.Text  '...Divya@29/01/2008
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "ccmDItemname_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmbSchType_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbSchType.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "cmbSchType_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub dtpickerFrom_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtpickerFrom.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "dtpickerFrom_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub dtPickerTo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dtPickerTo.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "dtPickerTo_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub cmbDiscType_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbDiscType.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "cmbDiscType_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtDiscount_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDiscount.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            If e.Shift Then e.SuppressKeyPress = True : Exit Sub
            Select Case e.KeyCode
                Case 222
                    e.SuppressKeyPress = True : Exit Sub
                Case Keys.Shift
                    e.SuppressKeyPress = True : Exit Sub
                Case Keys.Back, Keys.Delete, Keys.Tab, Keys.Home, Keys.End, Keys.Enter, Keys.Up, Keys.Left, Keys.Right, Keys.Down, Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9
                Case Keys.Decimal, Keys.OemPeriod
                    If sender.Text.IndexOf(".") >= 0 Then e.SuppressKeyPress = True : Exit Sub
                Case Else
                    e.SuppressKeyPress = True : Exit Sub

            End Select
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtDiscount_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub ccmbFreeItem_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ccmbFreeItem.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "ccmbFreeItem_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
    Private Sub txtremark_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtremark.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtremark_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub Display_Data()
        Dim dtDItemname As New DataTable
        Dim dtbFreeItem As New DataTable
        Try
            BCommon.SetDatePickerMaxMinDate(dtpickerFrom)
            BCommon.SetDatePickerMaxMinDate(dtPickerTo)
            BCommon.SetComboValues(cmbSchType, "SCHEMETYPE")
            BCommon.SetComboValues(cmbDiscType, "AMTTYPE")
            'Rahul_ITS@20071127:Add following line
            BCommon.SetComboValues(cmbAplTo, "SCHEME")
            dtDItemname = DItem.GetItems()
            dtbFreeItem = DItem.GetItems()
            ccmDItemname.DataSource = dtDItemname
            ccmbFreeItem.DataSource = dtbFreeItem
            ccmDItemname.Splits(0).DisplayColumns(2).Width = ccmDItemname.Width * 20 / 100
            ccmDItemname.Splits(0).DisplayColumns(1).Width = ccmDItemname.Width * 74 / 100
            ccmDItemname.Columns(2).Caption = "CODE"
            ccmDItemname.Columns(1).Caption = "ITEM NAME"
            ccmDItemname.Splits(0).DisplayColumns(0).Visible = False
            ccmDItemname.DisplayMember = "ItemName"
            ccmDItemname.ValueMember = "ItemID"
            ccmbFreeItem.Splits(0).DisplayColumns(2).Width = ccmbFreeItem.Width * 20 / 100
            ccmbFreeItem.Splits(0).DisplayColumns(1).Width = ccmbFreeItem.Width * 74 / 100
            ccmbFreeItem.Columns(2).Caption = "CODE"
            ccmbFreeItem.Columns(1).Caption = "ITEM NAME"
            ccmbFreeItem.Splits(0).DisplayColumns(0).Visible = False
            ccmbFreeItem.DisplayMember = "ItemName"
            ccmbFreeItem.ValueMember = "ItemID"
            GroupBox2.Visible = False
            GroupBox1.Height = GroupBox2.Top + 120
            lblRemark.Top = cmbAplTo.Bottom + 7
            txtremark.Top = cmbAplTo.Bottom + 7
            grpbbuttons.Top = GroupBox1.Bottom + 3
            Me.Height = grpbbuttons.Bottom + 35
            Dim pt As New Point
            pt.Y = ((MDIPharmacy.MdiScaleHeight - Me.Height) / 2) + MDIPharmacy.pnlHeading.Height + MDIPharmacy.MenuStrip.Height
            'pt.Y = (pnlShortcuts.Top - (pnlHeading.Top + pnlHeading.Height) - frmSchemeMaster.Height) / 2
            pt.X = (MDIPharmacy.MdiScaleWidth - Me.Width) / 2
            Me.Location = pt
            If itemid <> 0 Then
                ccmDItemname.Enabled = False
                ccmDItemname.SelectedValue = itemid
                ccmbFreeItem.Enabled = False           '...Divya@29/01/08
                ccmbFreeItem.SelectedValue = itemid    '...Divya@29/01/08
            End If
            'txtremark.Location = New Point(cmbDiscType.Left, cmbDiscType.Bottom + 10)
            'lblRemark
            btnDelete.Enabled = False
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "display_data")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Public Sub ViewData()
        Dim sch As CScheme

        sch = BScheme.GetScheme(intSchemeID)
        Try
            If sch.SchemeType = "D" Then
                cmbSchType.SelectedValue = "DISC"
            Else
                cmbSchType.SelectedValue = "FREEITEM"
            End If
            ccmDItemname.SelectedValue = sch.ItemID
            cmbDiscType.SelectedValue = sch.DiscountType
            ccmbFreeItem.SelectedValue = sch.schemeItemID
            cmbAplTo.SelectedValue = sch.ApllyTo
            txtDiscount.Text = sch.Discount
            dtpickerFrom.Value = sch.ValidFrom
            dtPickerTo.Value = sch.ValidTo
            txtMinqty1.Text = BCommon.InttoBlank(sch.SchemeMinQty1)
            txtMinqty2.Text = BCommon.InttoBlank(sch.SchemeMinQty2)
            txtMinqty3.Text = BCommon.InttoBlank(sch.SchemeMinQty3)
            txtFreeqty1.Text = BCommon.InttoBlank(sch.SchemeFreeQty1)
            txtFreeqty2.Text = BCommon.InttoBlank(sch.SchemeFreeQty2)
            txtFreeqty3.Text = BCommon.InttoBlank(sch.SchemeFreeQty3)
            txtremark.Text = sch.remarks
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "ViewData")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Public Sub ClearData()
        Try
            cmbSchType.SelectedIndex = -1
            ccmDItemname.SelectedIndex = -1
            cmbDiscType.SelectedIndex = -1
            ccmbFreeItem.SelectedIndex = -1
            'Rahul_ITS@20071127:Add following line
            cmbAplTo.SelectedIndex = -1
            txtDiscount.Text = ""
            dtpickerFrom.Value = Date.Now
            dtPickerTo.Value = Date.Now
            txtMinqty1.Text = ""
            txtMinqty2.Text = ""
            txtMinqty3.Text = ""
            txtFreeqty1.Text = ""
            txtFreeqty2.Text = ""
            txtFreeqty3.Text = ""
            txtremark.Text = ""
            ClearTag()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "Clear_Data")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Function ValidateData() As Boolean
        Try
            If ccmDItemname.SelectedIndex = -1 Then
                'Modified By:-Vinit(20071230)
                'BCommon.ShowMsgError(10201)
                BCommon.ShowMsgError(10234)
                ccmDItemname.Focus()
                Return False
            End If
            If Date.Compare(dtpickerFrom.Value.Date, Now.Date) < 0 Then
                BCommon.ShowMsgError(10202)
                dtpickerFrom.Focus()
                Return False
            End If
            If Date.Compare(dtPickerTo.Value.Date, Now.Date) < 0 Then
                BCommon.ShowMsgError(10203)
                dtPickerTo.Focus()
                Return False
            End If
            If Date.Compare(dtPickerTo.Value.Date, dtpickerFrom.Value.Date) < 0 Then
                BCommon.ShowMsgError(10204)
                dtPickerTo.Focus()
                Return False
            End If
            If cmbSchType.SelectedValue = "DISC" Then 'Discount
                If txtDiscount.Text = "" Then
                    BCommon.ShowMsgError(10206)
                    txtDiscount.Focus()
                    Return False
                ElseIf txtDiscount.Text = "0" Then
                    BCommon.ShowMsgError(10110)
                    txtDiscount.Focus()
                    Return False
                ElseIf txtDiscount.Text > 100 And cmbDiscType.SelectedValue = "P" Then
                    BCommon.ShowMsgError(10207)
                    txtDiscount.Focus()
                    Return False
                End If
            Else ' FREE ITEMS
                If ccmbFreeItem.SelectedIndex = -1 Then
                    BCommon.ShowMsgError(10205)
                    ccmbFreeItem.Focus()
                    Return False
                End If
                If txtMinqty1.Text = "" Then
                    BCommon.ShowMsgError(10209)
                    txtMinqty1.Focus()
                    Return False
                End If
                If txtFreeqty1.Text = "" Then
                    BCommon.ShowMsgError(10208)
                    txtFreeqty1.Focus()
                    Return False
                End If

            End If
            'Code End
            Return True
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "ValidateData")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    Private Sub SaveData()
        Try
            'Modified By:-Vinit(20071230)
            'If ValidateData() = False Then Exit Sub
            'Dim objScheme As New CScheme
            'objScheme = Setdata()
            'If btnSave.Text = "&Save" Then
            '    If BScheme.Save(objScheme, "S") > 0 Then BCommon.ShowMsgError(3) Else BCommon.ShowMsgError(4)
            'Else
            '    If BScheme.Save(objScheme, "U") > 0 Then BCommon.ShowMsgError(3) Else BCommon.ShowMsgError(4)
            'End If

            'Modified By:-Vinit(2008/01/23)
            Dim objScheme As New CScheme
            Dim intRetSchemeId As Integer = 0
            objScheme = Setdata()
            If btnSave.Text = "&Save" Then
                intRetSchemeId = BScheme.Save(objScheme, "S")
            Else
                intRetSchemeId = BScheme.Save(objScheme, "U")
            End If
            If intRetSchemeId > 0 Then
                BCommon.ShowMsgError(3)
                'Check the window status 
                'Whether this form has opened from master menu or transaction menu
                If strWindowFlag = "Y" Then intSchemeID = intRetSchemeId : setTag() : Me.Close() : Me.Cursor = Cursors.WaitCursor : Exit Sub
                '==========================================================================================
            Else
                BCommon.ShowMsgError(4)
            End If

            Call ClearData()
            Call Display_Data()
            btnSave.Text = "&Save"
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "SaveData")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub setTag()
        Try
            ccmDItemname.Tag = ccmDItemname.SelectedValue
            cmbSchType.Tag = cmbSchType.SelectedValue
            dtpickerFrom.Tag = dtpickerFrom.Value.Date
            dtPickerTo.Tag = dtPickerTo.Value.Date
            cmbDiscType.Tag = cmbDiscType.SelectedValue
            'cmbAplTo.Tag = cmbAplTo.Text

            'Rahul_ITS@20071127:Add following line
            cmbAplTo.Tag = cmbAplTo.SelectedValue
            txtDiscount.Tag = txtDiscount.Text
            ccmbFreeItem.Tag = ccmbFreeItem.SelectedValue
            txtMinqty1.Tag = txtMinqty1.Text
            txtFreeqty1.Tag = txtFreeqty1.Text
            txtMinqty2.Tag = txtMinqty2.Text
            txtFreeqty2.Tag = txtFreeqty2.Text
            txtMinqty3.Tag = txtMinqty3.Text
            txtFreeqty3.Tag = txtFreeqty3.Text
            txtremark.Tag = txtremark.Text
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "setTag")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub ClearTag()
        Try

            ccmDItemname.Tag = ""
            cmbSchType.Tag = ""
            dtpickerFrom.Tag = ""
            dtPickerTo.Tag = ""
            cmbDiscType.Tag = ""
            'Rahul_ITS@20071127:Add following line
            cmbAplTo.Tag = ""
            txtDiscount.Tag = ""
            ccmbFreeItem.Tag = ""
            txtMinqty1.Tag = ""
            txtFreeqty1.Tag = ""
            txtMinqty2.Tag = ""
            txtFreeqty2.Tag = ""
            txtMinqty3.Tag = ""
            txtFreeqty3.Tag = ""
            txtremark.Tag = ""
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "setTag")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Function isDirty() As Boolean
        Try
            If checkTag() Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "isUpdated")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    Private Function checkTag() As Boolean
        Try
            If ccmDItemname.SelectedValue <> ccmDItemname.Tag Or _
               cmbSchType.SelectedValue <> cmbSchType.Tag Or _
               cmbDiscType.SelectedValue <> cmbDiscType.Tag Or _
               cmbAplTo.SelectedValue <> cmbAplTo.Tag Or _
               dtpickerFrom.Value.Date <> dtpickerFrom.Tag Or _
               dtPickerTo.Value.Date <> dtPickerTo.Tag Or _
               Trim(txtDiscount.Text) <> txtDiscount.Tag Or _
               ccmbFreeItem.SelectedValue <> ccmbFreeItem.Tag Or _
               Trim(txtMinqty1.Text) <> txtMinqty1.Tag Or _
               Trim(txtFreeqty1.Text) <> txtFreeqty1.Tag Or _
               Trim(txtMinqty2.Text) <> txtMinqty2.Tag Or _
               Trim(txtFreeqty2.Text) <> txtFreeqty2.Tag Or _
               Trim(txtMinqty3.Text) <> txtMinqty3.Tag Or _
               Trim(txtFreeqty3.Text) <> txtFreeqty3.Tag Or _
               Trim(txtremark.Text) <> txtremark.Tag Then
                Return True
            Else : Return False
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "checkTag")
            Me.Cursor = Cursors.Default
        End Try
    End Function

    Private Function Setdata() As CScheme
        Dim objScheme As New CScheme
        Try
            With objScheme
                .SchemeID = intSchemeID
                .ItemID = ccmDItemname.SelectedValue
                .SchemeType = cmbSchType.SelectedValue
                .ValidFrom = dtpickerFrom.Value.Date
                .ValidTo = dtPickerTo.Value.Date
                .DiscountType = cmbDiscType.SelectedValue
                'Rahul_ITS@20071127:Add following line
                .ApllyTo = cmbAplTo.SelectedValue
                .Discount = Val(txtDiscount.Text)
                If .SchemeType = "F" Then
                    .schemeItemID = ccmbFreeItem.SelectedValue
                Else
                    .schemeItemID = 0
                End If
                .SchemeMinQty1 = Val(txtMinqty1.Text)
                .SchemeFreeQty1 = Val(txtFreeqty1.Text)
                .SchemeMinQty2 = Val(txtMinqty2.Text)
                .SchemeFreeQty2 = Val(txtFreeqty2.Text)
                .SchemeMinQty3 = Val(txtMinqty3.Text)
                .SchemeFreeQty3 = Val(txtFreeqty3.Text)
                .remarks = Trim(txtremark.Text)
            End With
            Return objScheme
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "Setdata")
            Me.Cursor = Cursors.Default
            Return Nothing
        End Try
    End Function

    Private Sub frmSchemeMaster_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Not (ConfigurationManager.AppSettings("FormMode") = "R") Then
            If isDirty() = True And btnSave.Enabled Then
                Select Case BCommon.ShowMsgError(10081, "YNC")
                    Case Windows.Forms.DialogResult.Yes
                        If ValidateData() = True Then
                            Call SaveData()
                        Else
                            e.Cancel = True
                        End If
                    Case Windows.Forms.DialogResult.Cancel
                        e.Cancel = True
                    Case Windows.Forms.DialogResult.No
                End Select
            End If
        End If
    End Sub

    Private Sub frmSchemeMaster_HelpButtonClicked(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.HelpButtonClicked
        'Rauhl_ITS@20073012 : Add following code display help
        'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Scheme Master")
        e.Cancel = True
    End Sub

    Private Sub frmSchemeMaster_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.F1 Then
            'Rauhl_ITS@20073012 : Add following code display help
            e.SuppressKeyPress = True
            'Help.ShowHelp(Me, "Pharma.chm", HelpNavigator.KeywordIndex, "Scheme Master")
        End If
    End Sub
    Private Sub frmSchemeMaster_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Call BCommon.SetFormStandards(Me)
            Call Display_Data()
            setTag()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "frmSchemeMaster_Load")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtMinqty1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMinqty1.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM")

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtMinqty1_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtFreeqty1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFreeqty1.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtFreeqty1_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtMinqty2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMinqty2.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtMinqty2_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtFreeqty2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFreeqty2.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtFreeqty2_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtMinqty3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMinqty3.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtMinqty3_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub txtFreeqty3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtFreeqty3.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
            e.SuppressKeyPress = Not BCommon.ValidateText(e.KeyCode, "NUM")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "txtFreeqty3_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            Me.Cursor = Cursors.Default
            If ValidateData() = True Then
                Call SaveData()
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "btnSave_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.Cursor = Cursors.WaitCursor
        Call ClearData()
        Call Display_Data()
        setTag()
        btnSave.Text = "&Save"
        btnSave.Enabled = True
        cmbSchType.Focus()
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Dim form As New frmMasterBrowse
        Try
            Me.Cursor = Cursors.WaitCursor
            form.strSearch = "Scheme"
            'Rahul_ITS@20072612
            '<<START
            form.StartPosition = FormStartPosition.Manual
            form.Height = MDIPharmacy.MdiScaleHeight
            form.Width = MDIPharmacy.MdiScaleWidth
            Dim pt As New Point
            pt.Y = ((MDIPharmacy.MdiScaleHeight - form.Height) / 2) + MDIPharmacy.pnlHeading.Height + MDIPharmacy.MenuStrip.Height
            pt.X = (MDIPharmacy.MdiScaleWidth - form.Width) / 2
            form.Location = pt
            form.ShowInTaskbar = False
            '>>END
            form.ShowDialog()
            intSchemeID = form.strRecordNo
            If intSchemeID <> 0 Then
                ClearData()
                Call ViewData()
                setTag()
                If Date.Compare(dtpickerFrom.Value.Date, Now.Date) <= 0 Then
                    btnSave.Enabled = False
                Else
                    btnSave.Text = "&Update"
                    If ConfigurationManager.AppSettings("FormMode") = "R" Then
                        btnDelete.Enabled = False
                        btnSave.Enabled = False
                    Else
                        btnDelete.Enabled = True
                        btnSave.Enabled = True
                    End If
                End If
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnSearch_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    Private Sub btnSearch_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.MouseLeave
        btnSearch.BackColor = Color.AliceBlue
        btnSearch.ForeColor = Color.Black
    End Sub

    Private Sub btnSearch_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnSearch.MouseMove
        btnSearch.BackColor = Color.LightSeaGreen
        btnSearch.ForeColor = Color.White
    End Sub

    Private Sub cmbSchType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbSchType.SelectedIndexChanged
        Try
            If cmbSchType.Text = "DISC" Or cmbSchType.Text = "Discount" Then
                txtDiscount.Visible = True
                lblDiscount.Visible = True
                lblDiscType.Visible = True
                cmbDiscType.Visible = True
                'Rahul_ITS@20071127:Add following code
                '<<START
                lblstar.Visible = True
                lblAplTo.Top = lblDiscType.Bottom + 18
                cmbAplTo.Top = cmbDiscType.Bottom + 9
                GroupBox2.Visible = False
                GroupBox1.Height = lblAplTo.Bottom + 80
                lblRemark.Top = cmbAplTo.Bottom + 9
                txtremark.Top = cmbAplTo.Bottom + 9
                grpbbuttons.Top = GroupBox1.Bottom
                Me.Height = grpbbuttons.Bottom + 35
                '>>END
            Else
                ccmbFreeItem.Enabled = False   '...Divya@29/01/2008
                ccmbFreeItem.Text = ccmDItemname.Text   '...Divya@29/01/2008
                txtDiscount.Visible = False
                lblDiscount.Visible = False
                lblDiscType.Visible = False
                cmbDiscType.Visible = False
                'Rahul_ITS@20071127:Add following code
                '<<START
                lblstar.Visible = False
                GroupBox2.Visible = True
                lblAplTo.Top = lblfrom.Bottom + 18
                cmbAplTo.Top = dtpickerFrom.Bottom + 9
                GroupBox2.Top = cmbAplTo.Bottom + 9
                lblRemark.Top = GroupBox2.Bottom + 9
                txtremark.Top = GroupBox2.Bottom + 9
                GroupBox1.Height = txtremark.Bottom + 10
                grpbbuttons.Top = GroupBox1.Bottom
                Me.Height = 470
                '>>END
            End If
            'Modified By:-VINIT(2008/01/23)
            'After Change the Scheme Type Set the Control Text and Tag
            setTag()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "cmbSchType_SelectedIndexChanged")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Private Sub cmbSchType_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbSchType.TextChanged
    '    Try
    '        '  If Not IsNothing(cmbSchType.SelectedText) Or cmbSchType.SelectedText <> "" Then
    '        If cmbSchType.SelectedValue <> "DISC" Then
    '            txtDiscount.Visible = False
    '            lblDiscount.Visible = False
    '            lblDiscType.Visible = False
    '            cmbDiscType.Visible = False
    '        End If
    '        ' End If
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "cmbSchType_SelectedIndexChanged")
    '    End Try
    'End Sub

    'Rahul_ITS@20071127:Add following line
    Private Sub cmbAplTo_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbAplTo.KeyDown
        Try
            If e.Alt Then Exit Sub
            If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "Pharmacy", Me.Name, "cmbAplTo_KeyDown")
            Me.Cursor = Cursors.Default
        End Try
    End Sub

    'Divya@29/01/2008 : Event added 
    Private Sub ccmDItemname_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ccmDItemname.Leave
        ccmbFreeItem.Text = ccmDItemname.Text
    End Sub

    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try
            Me.Cursor = Cursors.WaitCursor
            If (BScheme.IsSchemeUsed(intSchemeID)) = 0 Then
                If (BScheme.DeleteScheme(intSchemeID)) > 0 Then
                    BCommon.ShowMsgError(10377)
                    cmbSchType.Focus()
                    Call ClearData()
                    If btnSave.Text = "&Update" Then btnSave.Text = "&Save"
                    btnDelete.Enabled = False
                End If
            Else
                BCommon.ShowMsgError(10376)
                btnDelete.Focus()
            End If
            Me.Cursor = Cursors.Default
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, Me.ProductName, Me.Name, "btnDelete_Click")
            Me.Cursor = Cursors.Default
        End Try
    End Sub
End Class